//
// Decompiled by Jadx - 427ms
//
package me.plusne;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.res.XModuleResources;
import android.content.res.XResources;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.KeyEvent;
import androidx.appcompat.app.AppCompatActivity;
import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_InitPackageResources;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import fn.j;
import fn.q;
import fn.r;
import fn.s;
import fn.x;
import fn.u;
import fn.v;
import fn.w;
import fn.y;
import java.io.IOException;
import java.util.HashMap;
import me.plusne.common.Json.JsonHookStatic;
import r.a;

public class HookMain implements IXposedHookLoadPackage, IXposedHookZygoteInit, IXposedHookInitPackageResources {
    static {
        System.loadLibrary("dexkit");
    }

    public static class b extends x {
        public final void a() {
        }
    }

    public final void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam initPackageResourcesParam) {
    }

    public final void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) {
        if ("me.plusne".equals(loadPackageParam.packageName)) {
            XposedHelpers.findAndHookMethod(MainActivity.class.getName(), loadPackageParam.classLoader, "checkState", new Object[]{Boolean.TYPE, new XC_MethodHook(){
                public void beforeHookedMethod(XC_MethodHook.MethodHookParam methodHookParam) throws Throwable {
                    super.beforeHookedMethod(methodHookParam);
                    methodHookParam.args[0] = Boolean.FALSE;
                }
            }});
            return;
        }
        if (TextUtils.isEmpty(y.ca.get(loadPackageParam.packageName))) {
            return;
        }
        b bVar = new b();
        Thread.currentThread();
        JsonHookStatic jsonHookStatic = y.by;
        jsonHookStatic.setLpparam(loadPackageParam);
        ClassLoader classLoader = loadPackageParam.classLoader;
        y.bz = classLoader;
        jsonHookStatic.setClassLoader(classLoader);
        jsonHookStatic.setLooper(Looper.getMainLooper());
        jsonHookStatic.setMainHandler(new Handler(jsonHookStatic.getLooper()));
        jsonHookStatic.setSystemContext((Context) XposedHelpers.callMethod(XposedHelpers.callStaticMethod(XposedHelpers.findClass("android.app.ActivityThread", loadPackageParam.classLoader), "currentActivityThread", new Object[0]), "getSystemContext", new Object[0]));
        try {
            jsonHookStatic.setAppName(loadPackageParam.appInfo.loadLabel(jsonHookStatic.getSystemContext().getPackageManager()).toString());
            jsonHookStatic.setLastUpdateTime(jsonHookStatic.getSystemContext().getPackageManager().getPackageInfo(loadPackageParam.packageName, 0).lastUpdateTime);
            jsonHookStatic.setVersionCode(a.b(jsonHookStatic.getSystemContext(), loadPackageParam.packageName));
            jsonHookStatic.setVersionName(a.a(jsonHookStatic.getSystemContext(), loadPackageParam.packageName).versionName);
            try {
                j.a aVar = new j.a(jsonHookStatic.getModulePath());
                try {
                    ca.a h = aVar.h();
                    jsonHookStatic.setMainVersionCode(h.e.longValue());
                    jsonHookStatic.setMainVersionName(h.d);
                    aVar.close();
                } catch (Throwable th) {
                    try {
                        aVar.close();
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                    throw th;
                }
            } catch (IOException e) {
                e.printStackTrace();
                jsonHookStatic.setMainVersionCode(a.b(jsonHookStatic.getSystemContext(), "me.plusne"));
                jsonHookStatic.setMainVersionName(a.a(jsonHookStatic.getSystemContext(), "me.plusne").versionName);
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        String str = jsonHookStatic.getLpparam().packageName;
        HashMap hashMap = y.ca;
        if ((!TextUtils.isEmpty((CharSequence) hashMap.get(str))) && jsonHookStatic.getVersionCode() != 0 && !TextUtils.isEmpty(jsonHookStatic.getVersionName())) {
            if (!TextUtils.isEmpty(jsonHookStatic.getMainVersionName()) && jsonHookStatic.getMainVersionCode() >= 1) {
                q qVar = new q(bVar);
                XposedBridge.hookAllMethods(Activity.class, "onCreate", qVar);
                XposedBridge.hookAllMethods(Activity.class, "onResume", qVar);
                XposedBridge.hookAllMethods(AppCompatActivity.class, "onCreate", qVar);
                XposedBridge.hookAllMethods(AppCompatActivity.class, "onResume", qVar);
                XposedHelpers.findAndHookMethod(Application.class, "attach", new Object[]{Context.class, new r()});
                jsonHookStatic.setPre((String) hashMap.get(jsonHookStatic.getLpparam().packageName));
                XposedHelpers.findAndHookMethod(Application.class, "onCreate", new Object[]{new s(bVar)});
                u uVar = new u();
                v vVar = new v();
                w wVar = new w(uVar, vVar);
                XposedBridge.hookAllMethods(Activity.class, "onCreate", wVar);
                XposedBridge.hookAllMethods(AppCompatActivity.class, "onCreate", wVar);
                Class cls = Integer.TYPE;
                j.bf(Activity.class, "onKeyUp", new Object[]{cls, KeyEvent.class, uVar});
                j.bf(AppCompatActivity.class, "onKeyUp", new Object[]{cls, KeyEvent.class, uVar});
                j.bf(Activity.class, "onKeyDown", new Object[]{cls, KeyEvent.class, vVar});
                j.bf(AppCompatActivity.class, "onKeyDown", new Object[]{cls, KeyEvent.class, vVar});
                return;
            }
            j.bi(new Object[]{"模块错误,获取PlusNE信息失败,请检查是否隐藏PlusNE,或者没有给\"" + jsonHookStatic.getAppName() + "\"读取应用列表权限"});
        }
    }

    public final void initZygote(IXposedHookZygoteInit.StartupParam startupParam) {
        JsonHookStatic jsonHookStatic = y.by;
        jsonHookStatic.setModulePath(startupParam.modulePath);
        XModuleResources.createInstance(jsonHookStatic.getModulePath(), null);
    }
}
